<style scoped>
.pro-con {
    padding: 0 20px;
    margin-bottom: 50px;
}
.pro-con .ivu-form-item{
    margin-bottom: 0;
}
.hr{
    border:0;
    background-color:#DEDEDE;
    height:1px;
    margin: 15px 0;
}
.pro-con .ivu-col{
    padding-right: 0 !important;

}
 .fr{
    float: right;
}
.pro-pagesize .mr10{
    margin-right: 10px;
}
.search-h3{
    font-size: 18px;
    color: #ef8412;
    font-weight: normal;
    margin-bottom: 20px;
}


    /*//////////////////////////////*/

.pro-card {
    margin-bottom: 10px;
}
.pro-card-head {
    background-color: #e6e7eb;
    line-height: 38px;
    border: 1px solid #ddd;
}
.pro-card-title {
    font-size: 14px;
    color: #333;
    font-weight: bold;
    padding-left: 20px;
}
.pro-card-headr {
    padding-right: 10px;
    text-align: right;
}
.pro-card-content {
    clear: both;
}
.pro-paramname {
    text-align: center;
    background-color: #e6e7eb;
    font-size: 14px;
    color: #333;
    border-right: 1px solid #ddd;
}
.pro-paramvalue {
    padding-left: 30px;
    border-right: 1px solid #ddd;
}
.pro-card-contentrow {
    line-height: 40px;
    border-left: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}
.mb10{
    margin-bottom: 10px;
}
.search-h3{
    font-size: 18px;
    color: #ef8412;
    font-weight: normal;
    margin-bottom: 20px;
}
.search-form{
    border-bottom: 1px solid #d9d9d9;
}
.search-form .ivu-col{
    margin-bottom: 15px;
}
.clear{
    clear: both;
}
.table-theme{
    clear: both;
}
.table-action{
    padding-top: 10px;
    padding-bottom: 15px;
}
.inline-cut{
    margin-left: 15px;
    margin-right: 15px;
    width: 1px;
    height: 25px;
    background-color: #edf2f6;
}
.pro-pagesize{
    margin-bottom:10px;

}
.footer{
    position: fixed;
    padding: 0 30px;
    bottom:0;
    background-color:#FFF;
    box-shadow: -1px -3px 2px #E3E3E3;
}
.pro{
}
.pro_head_img{
}
.pro_show_img{
    position: relative;
    height:120px;
}
.close{
    width:15px;
    height:15px;
    position: absolute;
    right:7px;top:7px;
    border-radius: 50%;
    background-color:red;
    color:#FFF;
    line-height:15px;
    text-align: center;
    cursor: pointer;
}
.imgAdd{
    border:1px dotted #EEEEEE;
    height:50px;
    margin-top:10px;
    line-height: 50px;
    text-align: center;
    background-color: #FBFCFE;
}
.site-wrapper {
    width: 95%;
    margin: 0 auto;
}
.bm-view {
    width: 100%;
    height: 300px;
    margin-bottom: 20px;
}
.cropper-wrapper {
    margin-top: 10px;
    height: 400px;
}
.cropper-box{
    height: 300px;
}
.btn {
    display: inline-block;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    text-align: center;
    box-sizing: border-box;
    outline: none;
    margin:20px 10px 0px 0px;
    padding: 9px 15px;
    font-size: 14px;
    border-radius: 4px;
    color: #fff;
    background-color: #50bfff;
    border-color: #50bfff;
    transition: all .2s ease;
    text-decoration: none;
    user-select: none;
}
.iconclass{
    display: inline-block;
    width: 58px;
    background: #fff;
    border: 1px dashed #dddee1;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-color .2s ease;
    height:58px;
    line-height: 58px;
}
.cailiao{
    margin: 10px 0px 15px ;
}
    .cailiao span:first-child{
        display: inline-block;
        width: 20%;
        height: 36px;
        line-height: 36px;
        font-size: 14px;
        border: 1px solid #A9A9A9;
        border-right: 0;
        text-align: center;
        vertical-align: middle;
        background-color: #FAFAFA;
        font-weight: 500;
    }
.cailiao .inputBox{
    height: 36px;
    line-height: 34px;
    width: 80%;
    vertical-align: middle;
    padding-left: 5px;
    border:1px solid #A9A9A9;
    display: inline-block;
}
.cailiao .inputBox input{
    border: 0;
    width: 100%;
    outline: none;
}
#footer .ivu-btn-large{
    padding: 6px 10px 7px 10px;
}
</style>
<style>
    .duty .ivu-date-picker-rel:after, .duty .ivu-select:after {
        content: "";
        position: absolute;
        top: 1px;
        bottom: 1px;
        right: 1px;
        width: 35px;
        height: 34px;
        border-left: 1px solid #bebebe;
        background-color: #FAFAFA;
    }
    .duty .ivu-form .ivu-form-item-label{
        border:1px solid #BEBEBE;
        border-right: 0;
        background-color: #FAFAFA;
    }
    .duty .ivu-select-single .ivu-select-selection,.duty .ivu-input{
        height: 36px ;
        line-height: 36px;
        border-radius: 0 2px 2px 0;
        border-color: #BEBEBE;
    }
    .duty .ivu-select-single .ivu-select-selection .ivu-select-placeholder,.duty .ivu-select-single .ivu-select-selection .ivu-select-selected-value{
        height: 34px ;
        line-height: 34px;
        padding-right: 34px;
    }
    .duty .ivu-select-arrow{
        right:12px;
        z-index: 9;
    }
    .duty textarea.ivu-input{
        height: inherit;
    }
    .modal5 .ivu-modal-footer{
        background-color: #F2F2F2;
    }
    .table1 .ivu-table th{
        height:48px;
    }
</style>

<template>
    <div class="pro-list">
        <product-title></product-title>
        <div class="pro-con">
            <div class="pro-con-f common-box-body">
                <Row>
                    <h3 class="search-h3 huang">
                        快速搜索
                    </h3>
                        <Form  :model="searchForm" class="search-form">
                            <Col :xs="24" :sm="12" :md="12" :lg="6">
                                <Form-item>
                                    <Select size="large" v-model="searchForm.cid"  placeholder="供应商简称" filterable :transfer="true">
                                        <Option value=" ">全部</Option>
                                        <Option v-for="(item,index) in cname_list" :value="item.cid" :key="item.cid">{{item.shortn}}</Option>
                                    </Select>
                                </Form-item>
                            </Col>
                            <Col :xs="24" :sm="12" :md="12" :lg="6" style="padding-right:15px;">
                                <Form-item>
                                    <Input size="large" type="text"  v-model="searchForm.name" placeholder="产品名称" />
                                </Form-item>
                            </Col>
                            <Col :xs="24" :sm="12" :md="12" :lg="6" style="padding-right:15px;">
                                <Form-item>
                                    <Select size="large" v-model="searchForm.is_main" placeholder="主副险" :transfer="true">
                                        <Option value=" ">全部</Option>
                                        <Option value="1">主险</Option>
                                        <Option value="2">附加险</Option>
                                        <Option value="3">组合险</Option>
                                    </Select>
                                </Form-item>
                            </Col>
                            <Col :xs="24" :sm="12" :md="12" :lg="4" style="padding-right:15px;">

                            </Col>
                            <Col :xs="24" :sm="24" :md="24" :lg="2" >
                                <Form-item  style="padding-right:0px;">
                                    <Button size="large"  class="fr" type="primary" icon="ios-search" @click="search">搜索</Button>
                                </Form-item>
                            </Col>
                            <div class="clear"></div>
                        </Form>
                    <!--<i-col span="24">-->
                        <!--<hr class="hr">-->
                    <!--</i-col>-->
                </Row>
            </div>
            <div class="highlight_table">
                <Table stripe border :columns="columns1" :data="feeList" @on-current-change="currentChange" highlight-row class="table1"></Table>
            </div>
            <div id="footer" class="textL pt22">
            <Row>
                <i-col :md="6" :lg="6">
                    <i-button type="info" :disabled="disabled" @click="toDetail">编辑</i-button>
                    <!-- <i-button type="error" :disabled="disabled" @click="remove">删除</i-button> -->
                </i-col>
                <Col :md="18" :lg="18" class="textR">
                    <Page :total="listTotal" show-total show-sizer @on-change="pageChange" @on-page-size-change="pageSizeChange"  placement="top"></Page>
                </Col>
            </Row>
        </div>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import productTitle from '../../components/productTitle'
import { getFeeList,delFee,product_fee_times_save} from '../../api/fee'
// import { getRoleAll } from '../../api/role'





import {_fee_list,_fee_delete,_get_parter_list} from '../../api/product_v2'
import{product_fee_list} from '../../api/fee'
export default {
    data() {
        var  validateuser = function(rule, value, callback){
                    if(!value){
                        return callback(new Error("请输入用户名"));
                    }else if(!/^[a-zA-Z\d]+$/.test(value)){
                        return callback(new Error("请正确输入用户名"))
                    }else{
                        callback();
                    }
                };
        return {
            cname_list:[],
            columns1: [
                {
                    type: 'index',
                    
                    title:'序号',
                    width: 60,
                },
                {
                    title: '产品名称',
                    key: 'product_name',
                },
                {
                    title: '供应商简称',
                    key: 'com_parter_name',
                },
                {
                    title: '佣金系数',
                    key: 'fee',
                    // render:(h,params)=>{
                    //     return h('div',!params.row.fee?'暂无！请在改产品添加交费期间':params.row.fee)
                    // }
                },
                {
                    title: '主附险类型',
                    key: 'is_main',
                    render:(h,params)=>{
                        return h('div',(function(){
                                if(params.row.is_main==1){
                                    return '主险'
                                }else if(params.row.is_main==2){
                                    return '附加险';
                                }else if(params.row.is_main==3){
                                    return '组合险';
                                }else{
                                    return '暂无';
                                }
                            })()
                        )
                    }
                },
                // {
                //     title: '创建时间',
                //     key: 'create_timed',
                //     render:(h,params)=>{
                //         return h('div',params.row.create_timed.slice(0,10))
                //     }
                // },
                // {
                //     title: '修改时间',
                //     key: 'update_timed',
                //     render:(h,params)=>{
                //         return h('div',params.row.update_timed.slice(0,10))
                //     }
                // }
            ],
            feeList:[

            ],
            proList:[

            ],
            roleList:[

            ],
            //搜索的表格数据
            searchForm: {
                p:1,
                pagesize:10,
                cid:'',
                name:'',
                is_main:''
            }, 
            cateOneAll: [], //一级分类列表
            
            listTotal: 0, //产品总数
                                       
            page: 1,
            pagesize: 10,
            disabled:true,
        };
    },
    components: {
        productTitle
    },
    computed:{
        

    },
    created() {
        // this.getList()
        // // this.getProList()
        // this.getRole()
    },
    methods: {
        currentChange(current,oldCurrent){
            if(current.status==1){
                this.current = current;
                this.disabled = false;
            }else if(current.status==2){
                this.$Message.error('暂无佣金系数！请在该产品添加交费期间');
                this.disabled = true;
            }
            
        },
        all_company(){
            new Promise((resolve,reject)=>{
                _get_parter_list().then(res=>{
                    if(res.data.err==0){
                        this.cname_list = res.data.data;
                        //this.searchForm.cpid = this.$route.query.cpid
                    }else{
                        this.$Message.error(res.data.info);
                    }
                    resolve();
                }).catch(error=>{
                    reject(error);
                })
            })
        },
        //搜索
        search(){
           this.getList(); 
        },
        getList() {
            let _param = this.searchForm;
                _param.p = this.page;
                _param.pagesize = this.pagesize;
            new Promise((resolve, reject) => {
                product_fee_list(_param).then(response => {
                    if(response.data.err == 0){
                        this.feeList = response.data.data.list
                        this.listTotal = response.data.data.total
                    } else {
                        this.$Message.error(response.data.info);
                    }                       
                    resolve();
                }).catch(error => {
                    reject(error);
                });
            });
        },
        //获取产品列表
        // getProList() {
        //     new Promise((resolve, reject) => {
        //         getProListAll().then(response => {
        //             if(response.data.err == 0){
        //                 this.proList = response.data.data
        //             } else {
        //                 this.$Message.error(response.data.info);
        //             }                       
        //             resolve();
        //         }).catch(error => {
        //             reject(error);
        //         });
        //     });
        // },
        //获取角色列表
        // getRole() {
        //     new Promise((resolve, reject) => {
        //         getRoleAll().then(response => {
        //             if(response.data.err == 0){
        //                 this.roleList = response.data.data
        //             } else {
        //                 this.$Message.error(response.data.info);
        //             }                       
        //             resolve();
        //         }).catch(error => {
        //             reject(error);
        //         });
        //     });
        // },
        toDetail() {            
            this.$router.push({name:'fee_update',params:{ id:this.current.id }})
        },
        remove() {
            this.$Modal.confirm({
                title: '提示',
                content: '是否要删除该条记录?',
                onOk: () => {
                    var _param = {
                        fee_id:this.current.id
                    }
                    new Promise((resolve, reject) => {
                        _fee_delete(_param).then(response => {
                            console.log(response.data)
                            if(response.data.err == 0){
                                this.$Message.success(response.data.info);
                                this.getList();
                            } else {
                                this.$Message.error(response.data.info);
                            }                       
                            resolve();
                        }).catch(error => {
                            reject(error);
                        });
                    });
                },
            });
            
        },
        createPro() {
            this.$router.push({'name':'fee_create',params:{id:this.$route.params.id,name:this.$route.params.name}});
        },
        pageSizeChange(value){
            this.pagesize = value;
            this.p=1;
            this.getList();
        },
        pageChange(value){
             this.page = value;
             this.getList();
        }
                                                                                            
    },
    mounted () {
        this.getList()
        // this.getProList()
        // this.getRole()
        this.all_company();
    },

};
</script>
